/*
  Copyright � 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  ThanhNam ERP Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using VINETLIFE.DO;
/// <summary>
/// Summary description for cmsLogAccountDAL
/// </summary>
namespace VINETLIFE.DAL
{

    public class cmsLogAccountDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public cmsLogAccountDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(cmsLogAccountDO objcmsLogAccountDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsLogAccount_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@AccountId", SqlDbType.Int);
            Sqlparam.Value = objcmsLogAccountDO.AccountId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LogAccountType", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsLogAccountDO.LogAccountType;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LogAccountPaymentCode", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsLogAccountDO.LogAccountPaymentCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LogAccountPayment", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsLogAccountDO.LogAccountPayment;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Content", SqlDbType.NText);
            Sqlparam.Value = objcmsLogAccountDO.Content;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreatedDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsLogAccountDO.CreatedDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreatedById", SqlDbType.Int);
            Sqlparam.Value = objcmsLogAccountDO.CreatedById;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@FromCustomerId", SqlDbType.Int);
            Sqlparam.Value = objcmsLogAccountDO.FromCustomerId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OrderId", SqlDbType.Int);
            Sqlparam.Value = objcmsLogAccountDO.OrderId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DepositBeforeTran", SqlDbType.BigInt);
            Sqlparam.Value = objcmsLogAccountDO.DepositBeforeTran;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CurrentDeposite", SqlDbType.BigInt);
            Sqlparam.Value = objcmsLogAccountDO.CurrentDeposite;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Note", SqlDbType.NText);
            Sqlparam.Value = objcmsLogAccountDO.Note;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@TransactionDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsLogAccountDO.TransactionDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(cmsLogAccountDO objcmsLogAccountDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsLogAccount_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@LogAccountId", SqlDbType.Int);
            Sqlparam.Value = objcmsLogAccountDO.LogAccountId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@AccountId", SqlDbType.Int);
            Sqlparam.Value = objcmsLogAccountDO.AccountId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LogAccountType", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsLogAccountDO.LogAccountType;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LogAccountPaymentCode", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsLogAccountDO.LogAccountPaymentCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LogAccountPayment", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsLogAccountDO.LogAccountPayment;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Content", SqlDbType.NText);
            Sqlparam.Value = objcmsLogAccountDO.Content;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreatedDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsLogAccountDO.CreatedDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreatedById", SqlDbType.Int);
            Sqlparam.Value = objcmsLogAccountDO.CreatedById;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@FromCustomerId", SqlDbType.Int);
            Sqlparam.Value = objcmsLogAccountDO.FromCustomerId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OrderId", SqlDbType.Int);
            Sqlparam.Value = objcmsLogAccountDO.OrderId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DepositBeforeTran", SqlDbType.BigInt);
            Sqlparam.Value = objcmsLogAccountDO.DepositBeforeTran;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CurrentDeposite", SqlDbType.BigInt);
            Sqlparam.Value = objcmsLogAccountDO.CurrentDeposite;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Note", SqlDbType.NText);
            Sqlparam.Value = objcmsLogAccountDO.Note;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@TransactionDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsLogAccountDO.TransactionDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(cmsLogAccountDO objcmsLogAccountDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsLogAccount_DeleteByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@LogAccountId", SqlDbType.Int);
            Sqlparam.Value = objcmsLogAccountDO.LogAccountId;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsLogAccount_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public cmsLogAccountDO Select(cmsLogAccountDO objcmsLogAccountDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsLogAccount_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@LogAccountId", SqlDbType.Int);
            Sqlparam.Value = objcmsLogAccountDO.LogAccountId;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["LogAccountId"]))
                    objcmsLogAccountDO.LogAccountId = Convert.ToInt32(dr["LogAccountId"]);
                if (!Convert.IsDBNull(dr["AccountId"]))
                    objcmsLogAccountDO.AccountId = Convert.ToInt32(dr["AccountId"]);
                if (!Convert.IsDBNull(dr["LogAccountType"]))
                    objcmsLogAccountDO.LogAccountType = Convert.ToString(dr["LogAccountType"]);
                if (!Convert.IsDBNull(dr["LogAccountPaymentCode"]))
                    objcmsLogAccountDO.LogAccountPaymentCode = Convert.ToString(dr["LogAccountPaymentCode"]);
                if (!Convert.IsDBNull(dr["LogAccountPayment"]))
                    objcmsLogAccountDO.LogAccountPayment = Convert.ToString(dr["LogAccountPayment"]);
                if (!Convert.IsDBNull(dr["Content"]))
                    objcmsLogAccountDO.Content = Convert.ToString(dr["Content"]);
                if (!Convert.IsDBNull(dr["CreatedDate"]))
                    objcmsLogAccountDO.CreatedDate = Convert.ToDateTime(dr["CreatedDate"]);
                if (!Convert.IsDBNull(dr["CreatedById"]))
                    objcmsLogAccountDO.CreatedById = Convert.ToInt32(dr["CreatedById"]);
                if (!Convert.IsDBNull(dr["FromCustomerId"]))
                    objcmsLogAccountDO.FromCustomerId = Convert.ToInt32(dr["FromCustomerId"]);
                if (!Convert.IsDBNull(dr["OrderId"]))
                    objcmsLogAccountDO.OrderId = Convert.ToInt32(dr["OrderId"]);
                if (!Convert.IsDBNull(dr["DepositBeforeTran"]))
                    objcmsLogAccountDO.DepositBeforeTran = Convert.ToInt64(dr["DepositBeforeTran"]);
                if (!Convert.IsDBNull(dr["CurrentDeposite"]))
                    objcmsLogAccountDO.CurrentDeposite = Convert.ToInt64(dr["CurrentDeposite"]);
                if (!Convert.IsDBNull(dr["Note"]))
                    objcmsLogAccountDO.Note = Convert.ToString(dr["Note"]);
                if (!Convert.IsDBNull(dr["TransactionDate"]))
                    objcmsLogAccountDO.TransactionDate = Convert.ToDateTime(dr["TransactionDate"]);

            }
            return objcmsLogAccountDO;
        }

        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsLogAccount_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrcmsLogAccountDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    cmsLogAccountDO objcmsLogAccountDO = new cmsLogAccountDO();
                    if (!Convert.IsDBNull(dr["LogAccountId"]))
                        objcmsLogAccountDO.LogAccountId = Convert.ToInt32(dr["LogAccountId"]);
                    if (!Convert.IsDBNull(dr["AccountId"]))
                        objcmsLogAccountDO.AccountId = Convert.ToInt32(dr["AccountId"]);
                    if (!Convert.IsDBNull(dr["LogAccountType"]))
                        objcmsLogAccountDO.LogAccountType = Convert.ToString(dr["LogAccountType"]);
                    if (!Convert.IsDBNull(dr["LogAccountPaymentCode"]))
                        objcmsLogAccountDO.LogAccountPaymentCode = Convert.ToString(dr["LogAccountPaymentCode"]);
                    if (!Convert.IsDBNull(dr["LogAccountPayment"]))
                        objcmsLogAccountDO.LogAccountPayment = Convert.ToString(dr["LogAccountPayment"]);
                    if (!Convert.IsDBNull(dr["Content"]))
                        objcmsLogAccountDO.Content = Convert.ToString(dr["Content"]);
                    if (!Convert.IsDBNull(dr["CreatedDate"]))
                        objcmsLogAccountDO.CreatedDate = Convert.ToDateTime(dr["CreatedDate"]);
                    if (!Convert.IsDBNull(dr["CreatedById"]))
                        objcmsLogAccountDO.CreatedById = Convert.ToInt32(dr["CreatedById"]);
                    if (!Convert.IsDBNull(dr["FromCustomerId"]))
                        objcmsLogAccountDO.FromCustomerId = Convert.ToInt32(dr["FromCustomerId"]);
                    if (!Convert.IsDBNull(dr["OrderId"]))
                        objcmsLogAccountDO.OrderId = Convert.ToInt32(dr["OrderId"]);
                    if (!Convert.IsDBNull(dr["DepositBeforeTran"]))
                        objcmsLogAccountDO.DepositBeforeTran = Convert.ToInt64(dr["DepositBeforeTran"]);
                    if (!Convert.IsDBNull(dr["CurrentDeposite"]))
                        objcmsLogAccountDO.CurrentDeposite = Convert.ToInt64(dr["CurrentDeposite"]);
                    if (!Convert.IsDBNull(dr["Note"]))
                        objcmsLogAccountDO.Note = Convert.ToString(dr["Note"]);
                    if (!Convert.IsDBNull(dr["TransactionDate"]))
                        objcmsLogAccountDO.TransactionDate = Convert.ToDateTime(dr["TransactionDate"]);

                    arrcmsLogAccountDO.Add(objcmsLogAccountDO);
                }
            }
            return arrcmsLogAccountDO;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsLogAccount_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable SelectHistory(int accountId, string type, DateTime searchDate, DateTime fromDate, DateTime toDate, string logAccountPaymentCode)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "cmsLogAccount_GetHistory";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@AccountId", SqlDbType.Int);
            Sqlparam.Value = accountId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Type", SqlDbType.NVarChar);
            Sqlparam.Value = type;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@SearchDate", SqlDbType.DateTime);
            Sqlparam.Value = searchDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@FromDate", SqlDbType.DateTime);
            Sqlparam.Value = fromDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ToDate", SqlDbType.DateTime);
            Sqlparam.Value = toDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LogAccountPaymentCode", SqlDbType.NVarChar);
            Sqlparam.Value = logAccountPaymentCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable GetByAccountId(int accountId)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsLogAccount_GetByAccount";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@AccountId", SqlDbType.Int);
            Sqlparam.Value = accountId;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }



        #endregion

    }

}
